Doing More with Functions in JavaScript : See Closures, Variable Hoisting and Recursive Functions in Action by Rehan Zaidi

Doing More with Functions in JavaScript : See Closures, Variable Hoisting and Recursive Functions in Action by Rehan Zaidi

Author:Rehan Zaidi [Zaidi, Rehan]
Language: eng
Format: azw3
Published: 2019-02-11T16:00:00+00:00


Consider the following example:

function myFunction() {

var mytext = "Mytext";

function showtext() {

console.log(mytext);

}

showtext();

}

Function myFunction declares a local variable mytext and a function showtext - the inner function defined inside myFunction() that is available only in the body of myFunction. here, showtext has no local variables, but it has access to those of its outer functions, in this case myFunction. Within the myFunction body, we call the showtext function in order to displayed the text contained in variable mytext.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.